<?php
class Mod_danhsachphongkham extends CI_Controller{
    private $per_page = 10;
    private $total_rows =100;
    private $tb_phongkham = 'phongkham';
    function  __construct(){
        parent::__construct();
    }
    function index($data=array()){ // param 
        if(!empty($data)){
        $idchuyenkhoa = $data['idchuyenkhoa'];
        $phongkham = $data['phongkham'];
        $benhvien = $data['benhvien'];
        $iddiadiem = $data['iddiadiem'];        
        $offset = $data['offset'];
        }else{
            $idchuyenkhoa = $this->session->userdata('idchuyenkhoa');
            $phongkham = $this->session->userdata('phongkham'); 
            $benhvien = $this->session->userdata('benhvien'); 
            $iddiadiem = $this->session->userdata('iddiadiem');       
            $offset = $this->session->userdata('offset'); 
        }        
        if(empty($offset)) {$offset=0;} 
        $select = array('id','title','alias','introtext','address','hits');
        $order = array('truong'=>'point2','sapxep'=>'asc');
        ///check xem co phan trang khong//
        if(!empty($data['offset'])){
            echo '
                <script>
                $(document).ready(function(){   
                    $("html, body").animate({scrollTop:$("#modlistpk").position().top}, "slow");    
                });
                </script>';
        }
        
        //end
        if($idchuyenkhoa!=0){
            if(empty($iddiadiem)){
                if($phongkham==1&&$benhvien==1){
                   $where = array('idchuyenkhoa'=>$idchuyenkhoa,'publish'=>1); 
                }elseif($phongkham==1 && $benhvien==0){
                    $where = array('idchuyenkhoa'=>$idchuyenkhoa,'publish'=>1,'type'=>1);
                }elseif($phongkham==0 && $benhvien==1){
                    $where = array('idchuyenkhoa'=>$idchuyenkhoa,'publish'=>1,'type'=>2);
                }else $where = array('idchuyenkhoa'=>$idchuyenkhoa,'publish'=>1); 
                //print_r($where);
                
            }else{
                if($phongkham==1&&$benhvien==1){
                   $where = array('idchuyenkhoa'=>$idchuyenkhoa,'iddiadiem'=>$iddiadiem,'publish'=>1); 
                }elseif($phongkham==1 && $benhvien==0){
                    $where = array('idchuyenkhoa'=>$idchuyenkhoa,'iddiadiem'=>$iddiadiem,'publish'=>1,'type'=>1);                    
                }elseif($phongkham==0 && $benhvien==1){
                    $where = array('idchuyenkhoa'=>$idchuyenkhoa,'iddiadiem'=>$iddiadiem,'publish'=>1,'type'=>2);                
                }else $where = array('idchuyenkhoa'=>$idchuyenkhoa,'iddiadiem'=>$iddiadiem,'publish'=>1);
                
                
            } 
        }elseif($idchuyenkhoa==0){
            if(empty($iddiadiem)){
                if($phongkham==1&&$benhvien==1){
                   $where = array('publish'=>1); 
                }elseif($phongkham==1 && $benhvien==0){
                    $where = array('publish'=>1,'type'=>1);
                }elseif($phongkham==0 && $benhvien==1){
                    $where = array('publish'=>1,'type'=>2);
                }else $where = array('publish'=>1); 
                
            }else{
                if($phongkham==1&&$benhvien==1){
                   $where = array('iddiadiem'=>$iddiadiem,'publish'=>1); 
                }elseif($phongkham==1 && $benhvien==0){
                    $where = array('iddiadiem'=>$iddiadiem,'publish'=>1,'type'=>1);                    
                }elseif($phongkham==0 && $benhvien==1){
                    $where = array('iddiadiem'=>$iddiadiem,'publish'=>1,'type'=>2);                
                }else $where = array('iddiadiem'=>$iddiadiem,'publish'=>1);
                
                
            } 
        }
	    $datapk['phongkham'] = $this->home_model->get_data($this->tb_phongkham,$where,$order,$this->per_page,$select,$offset);
        $this->total_rows = $this->home_model->get_number($this->tb_phongkham,$where);        
        $this->phantrang();  
       $this->load->view('mod_danhsachphongkham/vmod_danhsachphongkham',$datapk);
    }
    function phantrang(){
        $this->load->library('pagination');
        $config['base_url'] = base_url().'danh-sach-phong-kham/';
        $config['total_rows'] = $this->total_rows;
        $config['per_page'] = $this->per_page;
        $config['uri_segment'] = 2;
        $config['num_links'] = 12;
        $this->pagination->initialize($config);
    
    }
}
?>